<template>
  <div class="container">


    <div class="header">
      <h3 class="title">订单发布</h3>
    </div>
    <div class="content-wrapper">
      <div class="main-card">
        <div class="card-title">发布订单</div>
        <div class="form-container">
          <van-form @submit="submitForm">
            <div class="form-card">
              <van-field v-model="formData.task" name="简介" label="简介" placeholder="请输入简介"
                :rules="[{ required: true, message: '请填写简介', trigger: 'onSubmit' }]" />

              <van-field v-model="formData.endTime" name="截止时间" label="截止时间" placeholder="请输入截止时间"
                :rules="[{ required: true, message: '请填写截止时间', trigger: 'onSubmit' }]" />

              <van-field v-model="formData.contact" name="联系方式" label="联系方式" placeholder="请输入联系方式"
                :rules="[{ required: true, message: '请填写联系方式', trigger: 'onSubmit' }]" />

              <van-field v-model="formData.content" name="详细描述" label="详细描述" type="textarea" rows="4" placeholder="请输入详细描述"
                :rules="[{ required: true, message: '请填写详细描述', trigger: 'onSubmit' }]" />

              <div class="form-item">
                <div class="item-label centered">图片补充</div>
                <van-uploader v-model="fileList" :max-count="4" :after-read="afterRead" class="custom-uploader" />
              </div>

              <div class="submit-btn-container">
                <van-button round block type="submit" class="submit-btn">发布</van-button>
              </div>
            </div>
          </van-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { showToast } from 'vant'

const router = useRouter()
const formData = ref({
  task: '',
  endTime: '',
  content: '',
  contact: ''
})

const fileList = ref([])

const afterRead = (file) => {
  // 此处是文件上传逻辑
}

const submitForm = () => {
  // 提交表单逻辑
}
</script>

<style scoped>
.container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: #c9d6e8;
}

.header {
  background-color: #4050B5;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  position: sticky;
  top: 0;
  z-index: 10;
}

.title {
  color: #fff;
  text-align: center;
  font-size: 18px;
  margin: 0;
  letter-spacing: 10px;
}

.content-wrapper {
  display: flex;
  justify-content: center;
  padding: 20px;
  flex: 1;
}

.main-card {
  width: 90%;
  background-color: #F7F7F7;
  border-radius: 30px;
  padding: 25px 20px;
  position: relative;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.card-title {
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  margin: 15px 0 30px;
  letter-spacing: 5px;
}

.form-item {
  background-color: white;
  border-radius: 15px;
  padding: 15px;
  margin-bottom: 15px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.item-label {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  margin-bottom: 8px;
}

.custom-field {
  background-color: #eceaea;
  border-radius: 10px;
  padding: 8px 12px;
  border: none;
}

.custom-field :deep(.van-field__control) {
  color: #333;
  text-align: left;
}

.custom-field :deep(.van-field__placeholder) {
  color: #000000;
  text-align: left;
}

.centered {
  text-align: center;
  width: 100%;
}

.custom-uploader {
  margin-top: 10px;
}

.custom-uploader :deep(.van-uploader__wrapper) {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-gap: 10px;
}

.custom-uploader :deep(.van-uploader__upload) {
  margin: 0;
  background-color: #eceaea;
  border-radius: 10px;
}

.custom-uploader :deep(.van-uploader__preview) {
  margin: 0;
  border-radius: 10px;
  overflow: hidden;
}

.submit-btn-container {
  margin-top: 25px;
}

.submit-btn {
  background-color: #4a5db7;
  border: none;
  color: white;
  font-size: 16px;
  font-weight: 500;
  height: 45px;
  border-radius: 25px;
  box-shadow: 0 6px 12px rgba(74, 93, 183, 0.5);
  transition: all 0.3s ease;
}

.submit-btn:active {
  transform: translateY(2px);
  box-shadow: 0 3px 6px rgba(74, 93, 183, 0.4);
}
</style>